home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / bas_int1.zip / @ISFILE.BAS < prev    next >
BASIC Source File  |  1991-07-03  |  2KB  |  67 lines

  1. '================================================================
  2. 'Two (2) routines are shown here to test for the existence
  3. 'of a file.  One uses CALL INTERRUPT.
  4. '=================================================================
  5. 'Quick Basic Forum
  6. '   Date : 28-Jun-91
  7. '   From : Dick Dennison
  8. 'Subject : Re: If Exist (file$) then
  9. '------------------------------------------------------------------
  10.  
  11. DECLARE FUNCTION Exist! (FileSpec$)
  12. '$INCLUDE: 'qb.bi'  'Supply correct path and start QB /L QB
  13.  
  14. a% = Exist("filename.ext")
  15. IF a% = -1 THEN PRINT "Exists" ELSE PRINT "Not found"
  16.  
  17. FUNCTION Exist (FileSpec$)
  18.            DIM regs AS RegTypeX
  19.            DIM DTA AS STRING * 44
  20.            Temp$ = FileSpec$ + CHR$(0)
  21.  
  22.            regs.ax = &H1A00                       'DOS service to set DTA
  23.            regs.ds = VARSEG(DTA)
  24.            regs.dx = VARPTR(DTA)
  25.            CALL INTERRUPTX(&H21, regs, regs)
  26.  
  27.            regs.ax = &H4E00                       'Find first matching file
  28.            regs.cx = 0
  29.            regs.ds = VARSEG(Temp$)
  30.            regs.dx = SADD(Temp$)
  31.            CALL INTERRUPTX(&H21, regs, regs)
  32.            IF regs.ax AND 255 THEN
  33.                   Exist = 0
  34.            ELSE
  35.                   Exist = -1
  36.            END IF
  37. END FUNCTION
  38.  
  39. '-------------------------------------------------------------------
  40. ' Quick Basic Forum
  41. '   Date : 30-Jun-91
  42. '   From : Steve Halko
  43. 'Subject : Re: If Exist (file$) then
  44.  
  45. 'Another method avoiding use of ON ERROR:
  46. '--------------------------------------------------------------------
  47.  
  48. FUNCTION Exist(FileName$) AS INTEGER
  49.     FileNr = FREEFILE
  50.     OPEN FileName$ FOR BINARY AS FileNr
  51.     IF LOF(FileNr) THEN
  52.         Exist = -1
  53.         CLOSE FileNr
  54.     ELSE
  55.         Exist = 0
  56.         CLOSE FileNr
  57.         KILL FileName$
  58.     ENDIF
  59. END FUNCTION
  60.  
  61.  
  62. 'This uses the fact that if you open a file for BINARY and the file
  63. 'didn't exist, then QB will create a file of length 0.  Of course, this
  64. 'won't work if you're trying to test for file of length 0 which already
  65. 'exists.
  66.  
  67.